import './App.css';
import React, { Suspense } from 'react';
import { createBrowserRouter, RouterProvider, Navigate } from 'react-router-dom';
import axios from 'axios';
axios.defaults.baseURL = 'http://localhost:3009';
// 杨旭
const Login = React.lazy(() => import('./views/login/Login'));
const Index = React.lazy(() => import('./views/Index'));
// 石路涛
const Complaint = React.lazy(() => import('./views/complaint/Complaint'));
const Complaintreport = React.lazy(() => import('./views/complaint/Complaintreport'));
const Mycomplaint = React.lazy(() => import('./views/complaint/Mycomplaint'));
const Complaintdetails = React.lazy(() => import('./views/complaint/Complaintdetails'));
// 尤帅凯
const SetUp = React.lazy(() => import('./views/Settings/SetUp'));
const Privacy = React.lazy(() => import('./views/Settings/Privacy'));
const Concerning = React.lazy(() => import('./views/Settings/Concerning'));
const Feedback = React.lazy(() => import('./views/Settings/Feedback'));
// 张贵天
const Homepage = React.lazy(() => import('./views/preamble/Homepage'));
const Xue = React.lazy(() => import('./views/preamble/Xue'));
const Details = React.lazy(() => import('./views/preamble/Details'));
// 唐佑超
const Mingchu = React.lazy(() => import('./views/Mingchu'));
const Jiankong = React.lazy(() => import('./views/Jiankong'));
const Shipin = React.lazy(() => import('./views/Shipin'));
// 李思雅
const School = React.lazy(() => import('./views/School'));
const Person = React.lazy(() => import('./views/Person'));
const StudentShiPu = React.lazy(() => import('./views/StudentShiPu'));
const Yyang = React.lazy(() => import('./views/Yyang'));
const YyangDetail = React.lazy(() => import('./views/YyangDetail'));
// 杨佳乐
const Mine = React.lazy(() => import('./views/My/MY'));
const Help = React.lazy(() => import('./views/My/Help.jsx'));
const Vpcc = React.lazy(() => import('./views/My/Vpcc'));
const Food = React.lazy(() => import('./views/My/Food.jsx'));
const Ingredient = React.lazy(() => import('./views/My/Ingredient.jsx'));
// 高文晗
const Hygiene = React.lazy(() => import('./views/Hygiene'));
const Acceptance = React.lazy(() => import('./views/Acceptance'));
const AcceptanceDetail = React.lazy(() => import('./views/AcceptaceDetail/index.jsx'));
const HygieneDetail = React.lazy(() => import('./views/HygieneDetail/index.jsx'));

// 路由守卫
function WithLogin(props) {
  if (localStorage.getItem('access_token')) {
    return props.children
  } else {
    return <Navigate to='/login' />
  }
}

const routers = [
  // 张贵天
  { path: '/', element: <Homepage /> }, // 首页
  { path: '/xue', element: <Xue /> }, // 选择学校页面
  { path: '/login', element: <Login /> },
  {
    path: '/index',
    element: <Index />,
    children: [
      { path: 'home', element: <Details /> },//首页
      {
        path: 'kitchen', element: <WithLogin><Mingchu /></WithLogin>,
        children: [
          { path: 'mingchu', element: <Navigate to="/index/kitchen/shipin"></Navigate> },
          { path: 'jiankong', element: <Jiankong /> }, //监控详情
          { path: 'shipin', element: <Shipin /> }, //监控详情
        ],
      },//明厨亮灶
      { path: 'mine', element: <Mine /> },//我的
    ]
  },
  // 杨佳乐
  { path: '/help', element: <Help></Help> },
  { path: '/vpcc', element: <Vpcc></Vpcc> },
  { path: '/food', element: <Food></Food> },
  { path: '/ingredient', element: <Ingredient></Ingredient> },
  //石陆涛            
  { path: '/complaint', element:<WithLogin><Complaint /></WithLogin>  }, //添加投诉
  { path: '/complaintRreport', element: <Complaintreport /> }, //投诉举报页面
  { path: '/mycomplaint', element: <WithLogin><Mycomplaint /></WithLogin> }, //我的投诉页面
  { path: '/complaintDetails', element: <Complaintdetails /> }, //投诉详情页面
  // 尤帅凯
  { path: '/setup', element: <SetUp /> }, // 设置页面
  { path: '/privacy', element: <Privacy /> }, // 隐私协议
  { path: '/concerning', element: <Concerning /> }, // 关于我们
  { path: '/feedback', element: <Feedback /> }, // 意见反馈
  //李思雅
  { path: '/school', element: <School /> },
  { path: '/person', element: <Person /> },
  { path: '/student', element: <StudentShiPu /> },
  { path: '/yang', element: <Yyang /> },
  { path: '/ydetail/:id', element: <YyangDetail /> },
  // 高文晗
  { path: '/Hygiene', element: <Hygiene /> },
  { path: '/Acceptance', element: <Acceptance /> },
  { path: '/HygieneDetail', element: <HygieneDetail /> },
  { path: '/AcceptanceDetail', element: <AcceptanceDetail /> },
]
const routeData = createBrowserRouter(routers);
function App() {
  return (
    <div className="App">
      {/* fallback释义回退, fall 下落，进入状态*/}
      <Suspense fallback={<div>加载中...</div>}>
        <RouterProvider router={routeData}>
        </RouterProvider>
      </Suspense>
    </div>
  );
}

export default App;
